/*
 * =====================================================================================
 *        Version:  1.0
 *        Created:  01/09/2012 02:30:34 PM
 *       Revision:  none
 *       Compiler:  gcc/g++
 *
 *         Author:  gnuhpc (http://www.cnblogs.com/gnuhpc), gnuhpc#gmail.com
 *        Company:  CMBC
 *
 * =====================================================================================
 */
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <cstdlib>
#include <cctype>
#include <sstream>
#include <numeric>
#include <map>

using namespace std;

int bitDiff(int a,int b)
{
	int result=0;
	for (int i = a^b;i!=0;i>>=1)
	{
		result+=i&1;
	}
	return result;
}

void swap(int& a, int& b)
{
	if (a!=b)
	{
		a=a^b;
		b=a^b;
		a=a^b;
	}
}

bool judgepower2(int n)
{
	return (n&(n-1))==0;
}

int ByteOrder()
{
	//return 0 for BIG_ENDIAN -- the most significant byte in the smallest address
	//return 1 for SMALL_ENDIAN-- the least significant byte in the smallest address
	short int word = 0x0001;
	char *byte = (char*) &word;
	return (byte[0]?1:0);
}

int main()
{
	int m = 12; //00001100
	int n = 134;//10000110
	cout << bitDiff(m,n) <<endl;
	swap(m,n);
	cout <<"m=" <<m <<",n=" << n<<endl;

	cout.setf(ios::boolalpha);
	cout << judgepower2(64) <<endl;
	cout << judgepower2(6) <<endl;

	cout << ByteOrder() <<endl;
	return 0;
}
